package backend;

import java.util.ArrayList;

public class Pipe implements Element {

	ArrayList<InputTypes> directions;

	public Pipe(ArrayList<InputTypes> directions) {

		this.directions = directions;
	}

	public ArrayList<InputTypes> getDirections() {
		return directions;
	}

	public InputTypes outDirection(InputTypes dir) {

		if (directions.size() == 4) {
			return dir;
		} else {
			if (dir == directions.get(0).oposite() && directions.size() == 2) {
				return directions.get(1);
			} else {
				return directions.get(0);
			}
		}
	}

	public boolean isCrossPipe() {
		return directions.size() == 4;
	}

	@Override
	public boolean canGo(InputTypes dir) {
		if (directions.contains(dir.oposite())) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {

		if (directions.size() == 4) {
			return "PIPE 7";
		}
		if (directions.contains(InputTypes.N)
				&& directions.contains(InputTypes.S))
			return "PIPE 5";
		if (directions.contains(InputTypes.W)
				&& directions.contains(InputTypes.E))
			return "PIPE 6";
		if (directions.contains(InputTypes.N)
				&& directions.contains(InputTypes.W))
			return "PIPE 1";
		if (directions.contains(InputTypes.N)
				&& directions.contains(InputTypes.E))
			return "PIPE 2";
		if (directions.contains(InputTypes.S)
				&& directions.contains(InputTypes.E))
			return "PIPE 3";
		if (directions.contains(InputTypes.W)
				&& directions.contains(InputTypes.S))
			return "PIPE 4";

		return super.toString();
	}

}
